<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=q54xW5I3uHC9g1MuXPV4r7yUANvybZYm"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=q54xW5I3uHC9g1MuXPV4r7yUANvybZYm"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }

        #allmap{
            height: 450px;
            width: 100%;
            overflow: hidden;
            font-family: "微软雅黑";
            border:1px solid green;
        }

        /*百度地图搜索框定位*/
        .tangram-suggestion-main {
            z-index: 999999;
        }
        /*设置弹出框样式*/
        .el-dialog__body {
            padding: 0px 20px;
            color: #606266;
            font-size: 14px;
        }
        /**/
        /*.el-input--suffix .el-input__inner {
            width: 450px;
        }*/
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>首页<small>公司分布图</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <template>
            <el-tabs v-model="activeName"  @tab-click="handleClick">
                <el-tab-pane label="分布图" name="first">
                    <div id="allmap"></div>
                   <!-- <div>
                        <button onclick='bdGEO()' class='btn'>批量解析</button>
                    </div>-->
                    <!--<iframe name="right" class="el-main" src="../bmaps/map.html" width="100%" height="580px" frameborder="0"></iframe>-->
                </el-tab-pane>

                <el-tab-pane label="详细信息" name="second">
                    <div class="filter-container">
                        <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="address" label="公司地址" align="center"></el-table-column>

                        <el-table-column prop="latitude" label="所在经度" align="center"></el-table-column>
                        <el-table-column prop="longitude" label="所在纬度" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
<!--                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>-->

                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                                class="pagiantion"
                                @current-change="handleCurrentChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                layout="total, prev, pager, next, jumper"
                                :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增地址" :visible.sync="dialogFormVisible" @opened="createMap">

                            <div class="filter-container">
                                <el-input id="suggestId" name="address_detail" placeholder="请输入要查询的地址" v-model="address_detail"  style="width: 400px;"></el-input>
                                <el-button type="primary" @click="handleAdd()" class="butT">确定添加</el-button>
                            </div>
                            <!--                            地址：<input type="text" id="suggestId" name="address_detail" placeholder="请输入要查询的地址" v-model="address_detail" class="input_style">-->
                            <div style="width:400px;height:400px;border:#ccc solid 1px;" id="l-map"></div>
                            <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
                        </el-dialog>
                    </div>
                </el-tab-pane>
            </el-tabs>
        </template>
    </div>
</div>

</body>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
            address_detail:'', //详细地址
            userlocation: {longitude: "", latitude: "",address: ""},
            adds:[]
        },
        mounted () {
        },
        created() {
            this.findPage();
            this.findAddress();
        },
        methods: {
            findAddress(){
                axios.post("/address/findAddress.do").then(res => {
                    if (res.data.flag){
                        this.adds = res.data.data;

                        var map = new BMapGL.Map('allmap');
                        map.centerAndZoom(new BMapGL.Point(114.309043,30.550317), 10);
                        map.enableScrollWheelZoom(true);
                        var myGeo = new BMapGL.Geocoder();

                        for (let i = 1; i< this.adds.length; i++){
                            myGeo.getPoint(vue.$data.adds[i], function(point){
                                if (point) {
                                    var address = new BMapGL.Point(point.lng, point.lat);
                                    var marker = new BMapGL.Marker(address);
                                    map.addOverlay(marker);
                                    marker.setLabel(new BMapGL.Label(i+":"+vue.$data.adds[i],{offset:new BMapGL.Size(10,-10)}));
                                }
                            }, "武汉市");
                        }
                    }

                })
            },


            createMap(){
                // 百度地图API功能
                function G(id) {
                    return document.getElementById(id);
                }

                var map = new BMap.Map("l-map");
                map.centerAndZoom("北京",12);                   // 初始化地图,设置城市和地图级别。

                var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
                    {"input" : "suggestId",
                        "location" : map
                    });

                ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
                    var str = "";
                    var _value = e.fromitem.value;
                    var value = "";
                    if (e.fromitem.index > -1) {
                        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    }
                    str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

                    value = "";
                    if (e.toitem.index > -1) {
                        _value = e.toitem.value;
                        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    }
                    //vue.$data.address_detail = value;
                    vue.$data.userlocation.address = value;
                    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
                    G("searchResultPanel").innerHTML = str;
                });

                var myValue;
                ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
                    var _value = e.item.value;
                    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
                    G("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;

                    setPlace();
                });

                function setPlace(){
                    map.clearOverlays();    //清除地图上所有覆盖物
                    function myFun(){
                        var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
                        vue.$data.userlocation.latitude = pp.lat;
                        vue.$data.userlocation.longitude = pp.lng;
                        map.centerAndZoom(pp, 18);
                        map.addOverlay(new BMap.Marker(pp));    //添加标注
                    }
                    var local = new BMap.LocalSearch(map, { //智能搜索
                        onSearchComplete: myFun
                    });
                    local.search(myValue);
                }

            },
            //分页查询
            findPage() {
                axios.post("/address/findPage.do", this.pagination).then(res => {
                    //res.data 就表示 pageresult对象
                    this.dataList = res.data.rows;
                    this.pagination.total = res.data.total;
                });

            },
            /*geocodeSearch(add){
                if(index < adds.length){
                    setTimeout(window.bdGEO,400);
                }
                myGeo.getPoint(add, function(point){
                    if (point) {
                        var address = new BMapGL.Point(point.lng, point.lat);
                        addMarker(address,new BMapGL.Label(index+":"+add,{offset:new BMapGL.Size(10,-10)}));
                    }
                }, "武汉市");
            },*/
            //查询地址
           /* findAddress(){
                axios.post("/address/findAddress.do").then(res =>{
                   //alert(res.data.data)
                    if(res.data.flag){
                        this.adds = res.data.data;
                        var map = new BMap.Map("allmap");    // 创建Map实例
                        map.centerAndZoom(new BMap.Point(113.41, 115.05), 11);  // 初始化地图,设置中心点坐标和地图级别
                        //添加地图类型控件
                        map.addControl(new BMap.MapTypeControl({
                            mapTypes:[
                                BMAP_NORMAL_MAP,
                                BMAP_HYBRID_MAP
                            ]}));
                        map.setCurrentCity("武汉");          // 设置地图显示的城市 此项是必须设置的
                        map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
                        var map = new BMapGL.Map("allmap");
                        map.centerAndZoom(new BMapGL.Point(114.2972392401123,30.588458371748413), 10);
                        map.enableScrollWheelZoom(true);
                        var myGeo = new BMapGL.Geocoder();
                        var index = 0;
                        if(index < this.adds.length){
                            setTimeout(window.bdGEO,400);
                        }
                        for (let i =0; i < this.adds.length; i++) {
                            myGeo.getPoint(vue.$data.adds[i], function (point) {
                                if (point) {
                                    var address = new BMapGL.Point(point.lng, point.lat);
                                    addMarker(address, new BMapGL.Label(index + ":" + vue.$data.adds[i], {offset: new BMapGL.Size(10, -10)}));
                                    var marker = new BMapGL.Marker(point);
                                    map.addOverlay(marker);
                                    marker.setLabel(label);
                                }
                            }, "武汉市");

                        }

                   }
                })
            },*/

            // 重置表单
            resetForm() {

            },

            // 弹出添加窗口
            handleCreate() {
                //1.显示窗口
                this.dialogFormVisible =true;
            },
            // 弹出编辑窗口
            handleUpdate(row) {

            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            // 删除
            handleDelete(row) {

            },
            //添加
            handleAdd(){
                //校验数据
                        axios.post("/address/add.do",this.userlocation).then((res) => {
                            if (res.data.flag) {
                                this.$message.success(res.data.message);
                                this.dialogFormVisible = false;
                                this.findPage();
                                this.findAddress();
                            } else {
                                this.$message.error(res.data.message);
                            }
                        }

                    );
            },
            handleClick(tab, event) {

            },

        }
    });
</script>
</html>
<!--<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("allmap");    // 创建Map实例
    map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);  // 初始化地图,设置中心点坐标和地图级别
    //添加地图类型控件
    map.addControl(new BMap.MapTypeControl({
        mapTypes:[
            BMAP_NORMAL_MAP,
            BMAP_HYBRID_MAP
        ]}));
    map.setCurrentCity("北京");          // 设置地图显示的城市 此项是必须设置的
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
   var map = new BMapGL.Map("allmap");
   map.centerAndZoom(new BMapGL.Point(117.269945,31.86713), 13);
   map.enableScrollWheelZoom(true);
   var myGeo = new BMapGL.Geocoder();
   var adds = [
       /*"包河区金寨路1号（金寨路与望江西路交叉口）",
       "庐阳区凤台路209号（凤台路与蒙城北路交叉口）",
       "蜀山区金寨路217号(近安医附院公交车站)",
       "蜀山区梅山路10号(近安徽饭店) ",
       "蜀山区 长丰南路159号铜锣湾广场312室",
       "合肥市寿春路93号钱柜星乐町KTV（逍遥津公园对面）",
       "庐阳区长江中路177号",
       "新站区胜利路89"*/
   ];
   var index = 0;
   function bdGEO(){
       if (index < adds.length) {
           var add = adds[index];
           geocodeSearch(add);
           index++;
       }
   }
   // 编写自定义函数,创建标注
   function addMarker(point,label){
       var marker = new BMapGL.Marker(point);
       map.addOverlay(marker);
       marker.setLabel(label);
   }


    loadMapAutocomplete("suggestId");
    function loadMapAutocomplete(mySuggestId) {
        Ac = new BMap.Autocomplete( //建立一个自动完成的对象
            {
                "input": suggestId,
            });
    }
</script>-->




